import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../generated/assets.dart';
import '../../theme/app_colors.dart';
import '../../utils/widget_util.dart';
import '../../widgets/gesture.dart';
import '../../widgets/text_widget.dart';
import '../login/login_logic.dart';
import 'register_logic.dart';

class RegisterPage extends StatelessWidget {
  final logic = Get.find<RegisterLogic>();
  final state = Get
      .find<RegisterLogic>()
      .state;
  final loginState = Get
      .find<LoginLogic>()
      .state;
  final loginLogic = Get.find<LoginLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 40.w),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              (ScreenUtil().screenHeight / 8).verticalSpace,
              Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  TextWidget(
                    "注册",
                    fontSize: 32.sp,
                    color: Color(0xFF242F44),
                    fontWeight: FontWeight.w500,
                  ),
                  Spacer(),
                  TextWidget(
                    "已有账号？",
                    color: Color(0xFFA6A6A6),
                  ),
                  ClickWidget(
                      onTap: logic.goToLogin,
                      child: TextWidget(
                        "立即登录",
                        color: primaryColor.withOpacity(0.8),
                      ))
                ],
              ),
              32.verticalSpace,
              WidgetUtil.inputWidget(placeHolder: "请输入用户名",height: 40.sp, onChanged: (value) {
                state.req.value.account = value;
              }),
              20.verticalSpace,
              WidgetUtil.inputWidget(placeHolder: "请输入手机号",height: 40.sp, onChanged: (value) {
                state.req.value.phone = value;
              }),
              20.verticalSpace,
              Row(
                children: [
                  Expanded(child: WidgetUtil.inputWidget(placeHolder: "请输入验证码",height: 40.sp, onChanged: (value) {
                    state.req.value.code = value;
                  }),),
                  20.horizontalSpace,
                  Expanded(
                    child: Obx(() {
                      return WidgetUtil.getCardItem(
                        onTap: state.getCode.value ? null : logic.sendCode,
                          padding: EdgeInsets.zero,
                          color: state.getCode.value ? Color(0xFFCCCCCC) : primaryColor.withOpacity(0.8),
                          child: Container(
                              height: 40.w,
                              alignment: Alignment.center,
                              child: TextWidget(state.codeBtnTitle.value, color: Colors.white, fontSize: 14.sp, fontWeight: FontWeight.w500,)));
                    }),
                  ),
                ],
              ),
              20.verticalSpace,
              WidgetUtil.inputWidget(obscureText: true, showReal: true,height: 40.sp, placeHolder: "请输入密码", onChanged: (value) {
                state.req.value.password = value;
              }),
              20.verticalSpace,
              WidgetUtil.inputWidget(obscureText: true, showReal: true,height: 40.sp, placeHolder: "请再次输入密码", onChanged: (value) {
                state.repeatPassword.value = value;
              }),
              48.verticalSpace,
              WidgetUtil.getCardItem(
                onTap: logic.registerAction,
                  padding: EdgeInsets.zero,
                  color: primaryColor.withOpacity(0.8),
                  child: Container(
                      height: 48.w,
                      alignment: Alignment.center,
                      child: TextWidget("注册", color: Colors.white, fontSize: 18.sp, fontWeight: FontWeight.bold,))),
              16.verticalSpace,
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Obx(() {
                    return WidgetUtil.imageBtn(imageName: loginState.read.value ? R.check : R.uncheck, size: 14, onTap: () {
                      loginState.read.value = !loginState.read.value;
                    });
                  }),
                  8.horizontalSpace,
                  TextWidget("我已阅读并同意", fontSize: 14, color: Color(0xFF999999),),
                  TextWidget(" 用户协议 ", fontSize: 14, color: primaryColor.withOpacity(0.8),),
                  TextWidget("和", fontSize: 14, color: Color(0xFF999999),),
                  TextWidget(" 隐私政策", fontSize: 14, color: primaryColor.withOpacity(0.8),),
                ],
              )
            ],
          ),
        ),
      ),
    );
  }
}
